package com.zhuzl.orderservice.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.zhuzl.orderservice.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JZY001
 * 下单接口
 */
@RestController
public class BusinessController {

    private final BusinessService businessService;

    @Autowired
    public BusinessController(BusinessService businessService) {
        this.businessService = businessService;
    }

    @RequestMapping("/createOrder")
    public String createOrder(@RequestParam("id") Integer id,
                              @RequestParam("count") Integer count,
                              @RequestParam(value = "orderErr", defaultValue = "false") Boolean orderErr,
                              @RequestParam(value = "hasError", defaultValue = "false") Boolean hasError) {
        if (ObjectUtils.isNull(id, count)) {
            return "参数不完整";
        }

        businessService.createOrder(id, count, orderErr, hasError);

        return "SUCCESS";
    }

}
